
//获取应用实例
var app = getApp()
Page({
  data: {
    callogs: [],
    openid:"oylh35BYfAbEyjlVXlpwHli7olwI"
  },
  onLoad: function () {
    //console.log("openid>>>" + wx.getStorageSync('openid'))
      var callogs =wx.getStorageSync('callogs');
      if (callogs == "" || callogs == null || callogs==undefined)
        callogs=["暂无计算记录"];
      this.setData({
        "callogs":callogs
      });
      var that = this;
      wx.login({
        success: (res) => {
          console.log("js_code:" + res.code)
          if (res.code) {
            wx.request({
              //url: "https://api.weixin.qq.com/sns/jscode2session",
              url: "https://www.webgang.xin/getOpenId.do",
              data: {
                //appid: getApp().globalData.appId,//你的appid
                //secret: getApp().globalData.secret,//你的secret
                appid: "wxb46564095a60706f",
                secret: "347993e818cff9f009b648573eea11b5",
                js_code: res.code,
                grant_type: "authorization_code"
              },
              success: (res) => {
                console.log(res);
                console.log("openid:" + res.data.openid)
               // wx.setStorageSync('openid', res.data.openid);
                that.setData({
                  openid: res.data.openid //存储openid
                })
              }
            })
          }
        }
      })
  },
  orderSign: function (e) {
    wx.showLoading({ //期间为了显示效果可以添加一个过度的弹出框提示“加载中”  
      title: '加载中',
      icon: 'loading',
    });
    var fId = e.detail.formId;
    console.log("fid:" + fId);
    // var l = 'https://api.weixin.qq.com/cgi-bin/message/wxopen/template/send?access_token=' + getApp().globalData.token;
    var l = 'https://www.webgang.xin/sendmsg.do';
    var d = {
      "keyword1": {
        "value": "00273",
        "color": "#4a4a4a"
      },
      "keyword2": {
        "value": "腾讯早餐店",
        "color": "#9b9b9b"
      },
      "keyword3": {
        "value": "66元",
        "color": "#9b9b9b"
      },
      "keyword4": {
        "value": "包子",
        "color": "#9b9b9b"
      },
      "keyword5": {
        "value": "68元",
        "color": "#9b9b9b"
      },
      "keyword6": {
        "value": "2015年01月05日 12:30",
        "color": "#9b9b9b"
      }
    };
    //  console.log(d)
    wx.request({
      url: l,
      header: {
        'content-type': 'application/json' // 默认值
      },
      data: {//注意不要用value代替data
        touser: this.data.openid,
        template_id: '7TOPafSsWbMsCPwJzlc7y9xD6bHxUZUW5g4uh566D_w',//申请的模板消息id，  
        page: '/pages/msg/msg',
        form_id: fId,
        data: d,
        color: '#ccc',
        emphasis_keyword: 'keyword1.DATA'
      },
      success: function (res) {
        wx.hideLoading();
        console.log("发送成功");
        console.log(res);
        wx.showToast({
          title: '推送成功啦~',
          icon: 'succes',
          duration: 1000,
          mask: true
        })
      },
      fail: function (err) {
        // fail  
        console.log("push err")
        console.log(err);
      }
    });
  }
})
